<?php

/**
* alltosun.com 活动widget events.php
* ============================================================================
* 版权所有 (C) 2009-2014 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* $Author: 吴松键 (wusj@alltosun.com) $
* $Date: 2014-9-3 下午5:35:25 $
* $Id$
*/

class events_widget
{
    private $page_no  = 1;
    private $per_page = 10;

    /**
     * 获取活动 无限加载列表
     */
    public function get_list($param = array())
    {
        $page_no = Request::getParam('page_no', 1);
        if (isset($param['per_page']) && $param['per_page']) {
            $this->per_page = $param['per_page'];
        }
        if (isset($param['page_no']) && $param['page_no']) {
            $page_no = $param['page_no'];
        }
        $filter['status'] = 1;

        $order = ' ORDER BY `id` DESC ';
        $limit = ' LIMIT '.($page_no-1)*$this->per_page.','.$this->per_page;

        $list = _model('events')->getList($filter, $order.$limit);

        return $list;
    }

    /**
     * 是否有更多的数据
     */
    public function has_more($param = array())
    {
        $page_no        = Request::getParam('page_no', 1);
        $this->per_page = Request::getParam('per_page', 1);
        if (isset($param['per_page']) && $param['per_page']) {
            $this->per_page = $param['per_page'];
        }
        if (isset($param['page_no']) && $param['page_no']) {
            $page_no = $param['page_no'];
        }
        $filter['status'] = 1;

        $total = _model('events')->getTotal($filter);

        $more_num = 0;
        if ($total > $page_no*$this->per_page) {
            $more_num = 1;
        }

        return $more_num;
    }
}
?>